﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Library.Definition;
using System.IO;

namespace Library.Heuristics.BowlingFeature
{
    public class BowlingFeatureHeuristics
    {
        public IDictionary<string, int> CountFrequency(string filename)
        {
            var fileLines = File.ReadAllLines(filename);
            var dictionary = GetDictionary();
            foreach (var fileLine in fileLines)
            {
                ISplitting splitter = new TruncatedSplitting();
                var words = splitter.WhiteSpaceBasedSplitting(fileLine);
                for (int i = 0; i < words.Count; i++)
                { 
                    if(dictionary.ContainsKey(words[i]))
                    {
                        dictionary[words[i]]++;
                    }
                }
            }

            return dictionary;
        }
        private IDictionary<string, int> GetDictionary()
        {
            BowlingFeatures bowlingFeature = BowlingFeatures.Length; 
            IDictionary<string, int> dictionary= new Dictionary<string, int>();
            var featureText = bowlingFeature.ToString();
            var assemblyResourcePath = "BallFeaturesText.BattingAidedBowlingFeatures.txt";
            var featureList = Library.BallType.GetFeatureList(assemblyResourcePath);
            foreach (var feature in featureList)
            {
                dictionary.Add(feature, 0); 
            }

            return dictionary;
        }
    }
}
